home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2006 May / PCWMAY06.iso / Software / Freeware / First Page 2006 3.00 / fp2006-final-3.00-setup.exe / {app} / Iscripts / Forms Misc / form-val.izs < prev    next >
Text File  |  2005-09-28  |  6KB  |  243 lines

  1. <!NOWIZARD>
  2.  
  3. <!TITLE>Form Validation
  4.  
  5. <!/TITLE>
  6.  
  7. <!DESCRIPTION> Use JavaScript to ensure that all elements of a form are properly filled out before they can be mailed to you. This definitely saves me from getting a lot of junk mail.... <!/DESCRIPTION> 
  8.  
  9. <!CATEGORY>Forms<!/CATEGORY>
  10.  
  11. <!SCRIPT>
  12. <!-- START OF SCRIPT -->
  13.  
  14. <!-- HOW TO INSTALL FORM VALIDATION:
  15.  
  16.    1.  Paste the first coding into the HEAD of your HTML document
  17.    2.  Put the last code into the BODY of your HTML document  -->
  18.  
  19. <!-- STEP ONE: Copy this code into the HEAD your HTML document  -->
  20.           
  21. <HEAD>
  22.  
  23. <SCRIPT LANGUAGE="JavaScript">
  24.  
  25.  
  26.  
  27. <!-- Begin
  28. function getCookie(name){
  29. var cname = name + "=";               
  30. var dc = document.cookie;             
  31. if (dc.length > 0) {              
  32. begin = dc.indexOf(cname);       
  33. if (begin != -1) {           
  34. begin += cname.length;       
  35. end = dc.indexOf(";", begin);
  36. if (end == -1) end = dc.length;
  37. return unescape(dc.substring(begin, end));
  38. }
  39. return null;
  40. }
  41. function setCookie(name, value) {
  42. var now = new Date();
  43. var then = new Date(now.getTime() + 31536000000);
  44. document.cookie = name + "=" + escape(value) + "; expires=" + then.toGMTString() + "; path=/";
  45. }
  46. function getInfo(form) {
  47. form.info.value = "Browser Information: " + navigator.userAgent;
  48. }
  49. function getValue(element) {
  50. var value = getCookie(element.name);
  51. if (value != null) element.value = value;
  52. }
  53. function setValue(element) {
  54. setCookie(element.name, element.value);
  55. }
  56. function fixElement(element, message) {
  57. alert(message);
  58. element.focus();
  59. }
  60. function isMailReady(form) {
  61. var passed = false;
  62. if (form.fullname.value == "") {
  63. fixElement(form.fullname, "Please include your name.");
  64. }
  65. else if (form.email.value.indexOf("@") == -1 ||
  66. form.email.value.indexOf(".") == -1) {
  67. fixElement(form.email, "Please include a proper email address.");
  68. }
  69. else if (form.message.value == "") {
  70. fixElement(form.message, "Please include a message.");
  71. }
  72. else {
  73. getInfo(form);
  74. passed = true;
  75. }
  76. return passed;
  77. }
  78. // End -->
  79. </SCRIPT>
  80.  
  81. <!-- STEP TWO: Add code into BODY section of document  -->
  82.  
  83. <BODY>
  84.  
  85. <CENTER>
  86. <FORM NAME = "mail" ACTION = "mailto:youremailaddress.com" METHOD = "POST" ENCTYPE = "text/plain" onSubmit = "return isMailReady(this);">
  87. <INPUT TYPE = "hidden" NAME = "info">
  88. <TABLE BORDER = 0 CELLPADDING = 5 CELLSPACING = 0>
  89. <TR>
  90. <TD>
  91. Your Name:
  92. <P>
  93. <INPUT TYPE = "TEXT" NAME = "fullname" onFocus = "getValue(this)" onBlur = "setValue(this)"> 
  94. </TD>
  95. <TD>
  96. Your Email Address:
  97. <P>
  98. <INPUT TYPE = "TEXT" NAME = "email" onFocus = "getValue(this)" onBlur = "setValue(this)">
  99. </TD>
  100. </TR>
  101. <TR>
  102. <TD COLSPAN = "2">
  103. Enter your Message:
  104. <P>
  105. <TEXTAREA ROWS = "8" COLS = "38" NAME = "message">
  106. </TEXTAREA>
  107. </TD>
  108. </TR>
  109. <TR>
  110. <TD COLSPAN = "2">
  111. <INPUT TYPE = "SUBMIT" VALUE = " Submit ">
  112. <INPUT TYPE = "RESET" VALUE = " Cancel ">
  113. </TD>
  114. </TR>
  115. </TABLE>
  116. </FORM>
  117. </CENTER>
  118.  
  119.  
  120.  
  121.  
  122. <!-- END OF SCRIPT -->
  123. <!/SCRIPT>
  124.  
  125. <!PREVIEW>
  126. <!-- START OF SCRIPT -->
  127.  
  128.  
  129. <!-- HOW TO INSTALL FORM VALIDATION:
  130.  
  131.    1.  Paste the first coding into the HEAD of your HTML document
  132.    2.  Put the last code into the BODY of your HTML document  -->
  133.  
  134. <!-- STEP ONE: Copy this code into the HEAD your HTML document  -->
  135.           
  136. <HEAD>
  137.  
  138. <SCRIPT LANGUAGE="JavaScript">
  139.  
  140.  
  141.  
  142. <!-- Begin
  143. function getCookie(name){
  144. var cname = name + "=";               
  145. var dc = document.cookie;             
  146. if (dc.length > 0) {              
  147. begin = dc.indexOf(cname);       
  148. if (begin != -1) {           
  149. begin += cname.length;       
  150. end = dc.indexOf(";", begin);
  151. if (end == -1) end = dc.length;
  152. return unescape(dc.substring(begin, end));
  153. }
  154. return null;
  155. }
  156. function setCookie(name, value) {
  157. var now = new Date();
  158. var then = new Date(now.getTime() + 31536000000);
  159. document.cookie = name + "=" + escape(value) + "; expires=" + then.toGMTString() + "; path=/";
  160. }
  161. function getInfo(form) {
  162. form.info.value = "Browser Information: " + navigator.userAgent;
  163. }
  164. function getValue(element) {
  165. var value = getCookie(element.name);
  166. if (value != null) element.value = value;
  167. }
  168. function setValue(element) {
  169. setCookie(element.name, element.value);
  170. }
  171. function fixElement(element, message) {
  172. alert(message);
  173. element.focus();
  174. }
  175. function isMailReady(form) {
  176. var passed = false;
  177. if (form.fullname.value == "") {
  178. fixElement(form.fullname, "Please include your name.");
  179. }
  180. else if (form.email.value.indexOf("@") == -1 ||
  181. form.email.value.indexOf(".") == -1) {
  182. fixElement(form.email, "Please include a proper email address.");
  183. }
  184. else if (form.message.value == "") {
  185. fixElement(form.message, "Please include a message.");
  186. }
  187. else {
  188. getInfo(form);
  189. passed = true;
  190. }
  191. return passed;
  192. }
  193. // End -->
  194. </SCRIPT>
  195.  
  196. <!-- STEP TWO: Add code into BODY section of document  -->
  197.  
  198. <BODY>
  199.  
  200. <CENTER>
  201. <FORM NAME = "mail" ACTION = "mailto:youremailaddress.com" METHOD = "POST" ENCTYPE = "text/plain" onSubmit = "return isMailReady(this);">
  202. <INPUT TYPE = "hidden" NAME = "info">
  203. <TABLE BORDER = 0 CELLPADDING = 5 CELLSPACING = 0>
  204. <TR>
  205. <TD>
  206. Your Name:
  207. <P>
  208. <INPUT TYPE = "TEXT" NAME = "fullname" onFocus = "getValue(this)" onBlur = "setValue(this)"> 
  209. </TD>
  210. <TD>
  211. Your Email Address:
  212. <P>
  213. <INPUT TYPE = "TEXT" NAME = "email" onFocus = "getValue(this)" onBlur = "setValue(this)">
  214. </TD>
  215. </TR>
  216. <TR>
  217. <TD COLSPAN = "2">
  218. Enter your Message:
  219. <P>
  220. <TEXTAREA ROWS = "8" COLS = "38" NAME = "message">
  221. </TEXTAREA>
  222. </TD>
  223. </TR>
  224. <TR>
  225. <TD COLSPAN = "2">
  226. <INPUT TYPE = "SUBMIT" VALUE = " Submit ">
  227. <INPUT TYPE = "RESET" VALUE = " Cancel ">
  228. </TD>
  229. </TR>
  230. </TABLE>
  231. </FORM>
  232. </CENTER>
  233.  
  234.  
  235.  
  236.  
  237. <!-- END OF SCRIPT -->
  238. <!/PREVIEW>
  239.  
  240. <!RELATED>NONE<!/RELATED>
  241.